﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace TestGraphicEnviroment
{
	class Solver
	{
		
		private static Point minPoint, maxPoint;
		private static Bitmap _input;
		private static int[ , ] _buffer;

		public Solver()
		{
		}

		public static List<Point> Step1( Bitmap b)
		{
			List<Point> result = new List<Point>();
			if( b == null )
				return result;

			_input = b;
			
			minPoint = new Point();
			maxPoint = new Point( b.Width, b.Height );
		
			
			for( int i = 0; i < maxPoint.X; ++i )
			{
				for( int j = 0; j < maxPoint.Y; ++j )
				{
					Point p = new Point( i, j );
					if( Neighberhood( p ) > 0 )
					{

						result.Add( new Point( maxPoint.X - i, j ) );
					}					
				}
			}

			return result;
		}


		private static int Neighberhood( Point p )
		{
			if( _input.GetPixel( p.X, p.Y ).ToArgb() == Color.FromKnownColor(KnownColor.Black).ToArgb() )
				return 0;
			
						   
			int startX, startY, endX, endY;
			startX = p.X - 1;
			startY = p.Y - 1;
			endX = p.X + 1;
			endY = p.Y + 1;

			if( startX < minPoint.X )
				startX = minPoint.X;
			if( startY < minPoint.Y )
				startY = minPoint.Y;

			if( endX >= maxPoint.X )
				endX = maxPoint.X - 1;

			if( endY >= maxPoint.Y )
				endY = maxPoint.Y - 1;

			int sum = 0;

			for( int i = startX; i <= endX; ++i )
			{
				for( int j = startY; j <= endY; ++j )
				{
					if( i == p.X && j == p.Y )
						continue;
					if( _input.GetPixel( i, j ).ToKnownColor() != KnownColor.Black)
						++sum;
				}
			}

			switch(sum)
			{
				case 0:
				case 5:
				case 6:				
				case 8:
					return 0;
				default: return sum;
			}
		}
	}
}
